<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>

        <ui:composition template="../templates/default3.xhtml">  

            <ui:define name="content">

                <h:form binding="#{jobManagerBean.loadUpdateJob}" id="updateJobForm">
                    <p:messages/>
                    <p:panel header="Job Information" id="addJob">
                        <table>
                            <tr>
                                <td width="135px"> Job ID:</td>
                                <td><b><h:outputText id="jobId" value=" #{jobManagerBean.job.jobId}"  /></b></td>
                            </tr>
                            <tr>
                                <td width="135px"> User ID:</td>
                                <td><b><h:outputText id="userId" value=" #{jobManagerBean.userId}"  /></b></td>
                            </tr>
                            <tr>
                                <td width="135px"> Company:</td>
                                <td><b><h:outputText id="company" value="#{jobManagerBean.customer.company}"  /></b></td>
                            </tr>
                            <tr>
                                <td>Person in-charge:</td>
                                <td><h:outputText id="name" value="#{jobManagerBean.customer.firstName} #{jobManagerBean.customer.lastName}"    /></td>
                            </tr>
                            <tr>
                                <td width="135px"> Date created:</td>
                                <td><b><h:outputText id="dateCreated" value=" #{jobManagerBean.job.jobDate}"> 
                                            <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                        </h:outputText>
                                    </b>
                                </td>
                            </tr>
                            <td>Job type:</td>
                            <td>
                                <h:selectOneMenu id="type" value="#{jobManagerBean.type}">
                                    <f:selectItem id="Normal" itemLabel="Normal Routine" itemValue="Normal Routine" />
                                    <f:selectItem id="New" itemLabel="New Routine" itemValue="New Routine" />
                                    <f:selectItem id="Event" itemLabel="Event" itemValue="Event" />
                                    <f:selectItem id="Rear" itemLabel="One-time" itemValue="One-time" />
                                </h:selectOneMenu>
                                <font class="fieldNote">*</font>
                            </td>
                            <tr>
                                <td valign ="top">Description:</td>
                                <td>
                                    <table>
                                        <tr>
                                            <td>
                                                <p:inputTextarea required="true" id="description" style="width:300px;height:100px;" effectDuration="400" requiredMessage="Description Required" value="#{jobManagerBean.description}"> 
                                                </p:inputTextarea>
                                            </td>
                                            <td>
                                                <font class="fieldNote">*</font>
                                            </td>
                                        </tr>
                                    </table> 
                                </td>
                            </tr>
                        </table>
                    </p:panel>

                    <p:panel header="Quotations" id="quotes">

                        <p:dataTable id="quotation" var="quotation" value="#{jobManagerBean.quotations}" paginator="false"                                     
                                     emptyMessage="No quotations found with given criteria."
                                     selectionMode="single" rowSelectListener="#{jobManagerBean.onRowSelect}"
                                     selection="#{jobManagerBean.selectedQuotation}">     
                            <p:column headerText="Quotation ID"> 
                                <h:outputText value="#{quotation.id}" />                                             
                            </p:column> 
                            <p:column headerText="Date created"> 
                                <h:outputText value="#{quotation.creationDate}"> 
                                    <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>                                             
                            </p:column> 
                            <p:column headerText="Amount involved"> 
                                <h:outputText value="#{quotation.totalAmount}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Status"> 
                                <h:outputText value="#{quotation.status}" />                                             
                            </p:column> 
                            <p:column headerText="Remark"> 
                                <h:outputText value="#{quotation.remark}" />                                             
                            </p:column> 

                        </p:dataTable>
                        <p:commandButton id="btnAddForOldJob" value="Add a Quotation" actionListener="#{jobManagerBean.addQuotation}"  update="updateJobForm" ajax="true" /> 



                    </p:panel>

                    <p:panel header="Quotations" id="purchaseOrders" rendered="#{jobManagerBean.renderConvert}">

                        <p:dataTable id="purchaseOrder" var="purchaseOrder" value="#{jobManagerBean.purchaseOrder}" paginator="false"                                     
                                     emptyMessage="No quotations found with given criteria.">     
                            <p:column headerText="P/O number"> 
                                <h:outputText value="#{purchaseOrder.poNumber}" />                                             
                            </p:column> 
                            <p:column headerText="Date created"> 
                                <h:outputText value="#{purchaseOrder.poDate}"> 
                                    <f:convertDateTime pattern="dd-MM-yyyy hh:mm a" timeZone="#{defaultManagerBean.tz}"/>
                                </h:outputText>                                             
                            </p:column> 
                            <p:column headerText="Amount involved"> 
                                <h:outputText value="#{purchaseOrder.totalAmount}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column> 
                            <p:column headerText="Status"> 
                                <h:outputText value="#{purchaseOrder.status}" />                                             
                            </p:column> 
                            <p:column headerText="Remark"> 
                                <h:outputText value="#{purchaseOrder.remark}" />                                             
                            </p:column> 

                        </p:dataTable>

                    <p:commandButton id="btnConvert" value="Convert to Sales Order" ajax="true"  title="Convert the Active quotation in this job to a sales order. Expired quotations cannot be converted."
                                     rendered="#{jobManagerBean.renderConvert}" onclick="confirmation.show()" />

                    <p:confirmDialog  width="400" message="" header="Converting the active quotation in this job to a sales order" severity="alert" widgetVar="confirmation">
                        <f:facet name="message">
                            <h:outputText value="Converting the Active quotation in this job to a sales order. It may start off other finance and inventory processes."/><br/>
                            <br/>
                            <h:outputText value="Are you sure you want to continue?"/>
                        </f:facet>    
                        <p:commandButton value="Yes" update="quotationInformationPanel" oncomplete="confirmation.hide()"
                                         actionListener="#{jobManagerBean.convertToSalesOrder}"/>
                        <p:commandButton value="No"  onclick="confirmation.hide()" type="button" />
                    </p:confirmDialog>
                    </p:panel>

                    <table width="100%" border="0">
                        <tr>
                            <td class="btn">
                                <p:commandButton id="btndone" value="Done" actionListener="#{jobManagerBean.doneUpdate}"  update="updateJobForm" ajax="true" /> 
                            </td>
                        </tr>
                    </table>






                </h:form>
            </ui:define>

        </ui:composition>

    </body>
</html>
